 package uk.co.mmscomputing.concurrent;
 
 public class Semaphore
 {
   private int initpermits;
   private int available;
   private int waiting;
 
   public Semaphore(int paramInt, boolean paramBoolean)
   {
     this.initpermits = paramInt;
     this.available = this.initpermits;
     this.waiting = 0;
   }
   public boolean isFair() {
     return true; } 
   public int availablePermits() { return this.available; }
 
 
   public synchronized void acquire()
     throws InterruptedException
   {
     while (this.available <= 0) {
       try {
         this.waiting += 1;
         wait();
 
         this.waiting -= 1; } finally { this.waiting -= 1; }
 
     }
     this.available -= 1;
   }
 
   public synchronized boolean tryAcquire(long paramLong, TimeUnit paramTimeUnit) throws InterruptedException {
     if (this.available <= 0) {
       if (paramLong <= 0L) return false; try
       {
         this.waiting += 1;
         wait(paramLong);
       } finally {
         this.waiting -= 1;
       }
       if (this.available <= 0) return false;
     }
     this.available -= 1;
     return true;
   }
 
   public synchronized void release() {
     this.available += 1;
     if ((this.available > 0) && (this.waiting > 0))
       notify();
   }
 
   public void release(int paramInt)
   {
     for (int i = 0; i < paramInt; i++)
       release();
   }
 }

